package com.onlinemarket.thrid.daoimpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.onlinemarket.thrid.dao.loginDao;
import com.onlinemarket.thrid.domain.User;

@Repository
public class loginImpl implements loginDao {
	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Override
	public boolean checkUser(String user_name, String user_password) {
		String psw = "";
		String sql = "select user_password from user where user_name=?";
		psw = jdbcTemplate.queryForObject(sql, String.class, new Object[] { user_name });
		return psw.equals(user_password) ? true : false;
	}

	/**
	 * 判断是否已存在相同的用户名
	 */
	@Override
	public boolean alreadHasUser(String username) {
		// TODO Auto-generated method stub
		User user = new User();
		String sql = "select * from user where user_name = ?";
		List<User> userlist = jdbcTemplate.queryForList(sql, User.class, new Object[] { username });
		return userlist == null ? true:false;
	}
}
